Sys.Application.add_init(appinit);

function appinit(sender, initEventArgs) {
    
    var prm = Sys.WebForms.PageRequestManager.getInstance();
    
    prm.add_initializeRequest(initReq);
    prm.add_beginRequest(beginReq);
    prm.add_pageLoading(pageLoading);
    prm.add_pageLoaded(pageLoaded);
    prm.add_endRequest(endRequest);    
}

function initReq(sender, initReqEventArgs) {
    var one = 1; ///do nothing, just a breakpoint
}
function beginReq(sender, beginReqEventArgs) {
    var one = 1; ///do nothing, just a breakpoint
}
function pageLoading(sender, pageLoadingEventArgs) {
    var one = 1; ///do nothing, just a breakpoint
}
function pageLoaded(sender, pageLoadedEventArgs) {
    
    var content = pageLoadedEventArgs._panelsUpdated[0].innerHTML;
    var favs = eval(content).Favorites;
    
    if(favs) {
    
        var sbContent = new Sys.StringBuilder('<ul>');
        var mask = "<li><a href='{0}'>{1}</a></li>";
        var line = new String;
        
        for (x=0; x<favs.length; x++) {
            line = String.format(mask, favs[x].URL, favs[x].Name);
            sbContent.append(line);    
        }
        
        sbContent.append('</ul>');
        
        pageLoadedEventArgs._panelsUpdated[0].innerHTML = sbContent.toString();
    }
    
}
function endRequest(sender, endRequestEventArgs) {
    var one = 1; ///do nothing, just a breakpoint
}